﻿//using System.Text.Encodings.Web;
//using System.Text.Json;
//using System.Text.Unicode;

//namespace NiuX.Json;

//public static class SystemJsonExtensions
//{
//    //如果不设置这个，那么"雅思真题"就会保存为"\u96C5\u601D\u771F\u9898"
//    public readonly static JavaScriptEncoder Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);

//    private static readonly JsonSerializerOptions DefaultOptions = new JsonSerializerOptions
//    {
//        Encoder = Encoder
//    };


//    public static JsonSerializerOptions CreateJsonSerializerOptions(bool camelCase = false)
//    {
//        //JsonSerializerOptions opt = new JsonSerializerOptions { Encoder = Encoder };
//        //if (camelCase)
//        //{
//        //    opt.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;
//        //    opt.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
//        //}
//        //opt.Converters.Add(new DateTimeJsonConverter("yyyy-MM-dd HH:mm:ss"));
//        return DefaultOptions;
//    }

//    public static string ToJsonString(this object value, bool camelCase = false)
//    {
//        var opt = CreateJsonSerializerOptions(camelCase);
//        return JsonSerializer.Serialize(value, value.GetType(), opt);
//    }

//    public static T? FromJson<T>(this string value)
//    {
//        if (string.IsNullOrWhiteSpace(value))
//        {
//            return default(T);
//        }
//        var opt = CreateJsonSerializerOptions();
//        return JsonSerializer.Deserialize<T>(value, opt);
//    }
//}